package com.magic.easyexcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.*;

/**
 * @author laoma
 * @create 2021-06-06 11:06
 */
public class EasyTest {
    public static void main(String[] args) {
        List<Map<Integer,String>> list = new LinkedList<>();
        EasyExcel.read("F:\\java-workspace\\malearn\\easyexcel\\listener.xlsx")
                .sheet()
                // .head() 返回实体映射类型，默认是 LinkHashMap
                .registerReadListener(new AnalysisEventListener<Map<Integer,String>>() {

                    @Override
                    public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
                        list.add(integerStringMap);
                    }

                    @Override
                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                        System.out.println("数据读取完毕");
                    }
                }).doRead();
        for (Map<Integer, String> integerStringMap : list) {
            Set<Integer> keySet = integerStringMap.keySet();
            Iterator<Integer> iterator = keySet.iterator();
            while (iterator.hasNext()) {
                Integer key = iterator.next();
                System.out.print(key+":"+integerStringMap.get(key)+", ");
            }
            System.out.println();
        }
    }
}
